package com.im.service.friendship.controller;

import com.im.common.model.RestResponse;
import com.im.service.friendship.model.req.AddFriendShipGroupMemberReq;
import com.im.service.friendship.model.req.AddFriendShipGroupReq;
import com.im.service.friendship.model.req.DeleteFriendShipGroupMemberReq;
import com.im.service.friendship.model.req.DeleteFriendShipGroupReq;
import com.im.service.friendship.service.ImFriendShipGroupMemberService;
import com.im.service.friendship.service.ImFriendShipGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "好友分组控制器")
@RestController
@RequestMapping("/v1/friendship/group")
public class ImFriendShipGroupController {

    @Autowired
    ImFriendShipGroupService imFriendShipGroupService;
    @Autowired
    ImFriendShipGroupMemberService imFriendShipGroupMemberService;

    @ApiOperation("添加分组")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public RestResponse add(@RequestBody @Validated AddFriendShipGroupReq req, Integer appId) {
        req.setAppId(appId);
        imFriendShipGroupService.addGroup(req);
        return RestResponse.success();
    }

    @ApiOperation("删除分组")
    @RequestMapping(value = "/del", method = RequestMethod.POST)
    public RestResponse del(@RequestBody @Validated DeleteFriendShipGroupReq req, Integer appId) {
        req.setAppId(appId);
        imFriendShipGroupService.deleteGroup(req);
        return RestResponse.success();
    }

    @ApiOperation("添加分组成员")
    @RequestMapping(value = "/member/add",method = RequestMethod.POST)
    public RestResponse memberAdd(@RequestBody @Validated AddFriendShipGroupMemberReq req, Integer appId) {
        req.setAppId(appId);
        List<String> strings = imFriendShipGroupMemberService.addGroupMember(req);
        return RestResponse.success(strings);
    }

    @ApiOperation("删除分组成员")
    @RequestMapping(value = "/member/del",method = RequestMethod.POST)
    public RestResponse memberDel(@RequestBody @Validated DeleteFriendShipGroupMemberReq req, Integer appId) {
        req.setAppId(appId);
        List<String> strings = imFriendShipGroupMemberService.delGroupMember(req);
        return RestResponse.success(strings);
    }

}
